from PIL import Image
import numpy as np
from moviepy.editor import ImageClip, VideoClip

# 读取美女照片
image_path = r'../../img/beauty02.png'  # 替换为你的图片路径
image = Image.open(image_path)
image = np.array(image)

# 创建倒影图像
reflected_image = np.flipud(image)

# 添加渐变透明度
height, width, _ = image.shape
alpha = np.linspace(1, 0, height)
alpha = np.repeat(alpha[:, np.newaxis], width, axis=1)
alpha = np.repeat(alpha[:, :, np.newaxis], 3, axis=2)
reflected_image = (reflected_image * alpha).astype(np.uint8)

# 合并原图和倒影
combined_image = np.vstack((image, reflected_image))

# 定义水纹波动函数
def water_wave(t):
    new_image = combined_image.copy()
    height, width, _ = new_image.shape
    for y in range(height):
        for x in range(width):
            new_x = x + int(10 * np.sin(0.02 * y + 0.1 * t))
            if 0 <= new_x < width:
                new_image[y, x] = combined_image[y, new_x]
    return new_image

# 创建视频剪辑
duration = 10  # 视频时长（秒）
fps = 25  # 帧率
video_clip = VideoClip(lambda t: water_wave(t), duration=duration)

# 保存视频
video_clip.write_videofile('water_effect_video.mp4', fps=fps)
